﻿using System;
using SharpSqlAnalyzer.nodes;

namespace SharpSqlAnalyzer.stmt.mssql
{
	// Token: 0x02000175 RID: 373
	public class TMssqlExecute : TCustomSqlStatement
	{
		// Token: 0x06000CEA RID: 3306 RVA: 0x00307ED4 File Offset: 0x003060D4
		public TMssqlExecute(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstmssqlexec;
		}

		// Token: 0x06000CEB RID: 3307 RVA: 0x00307EE8 File Offset: 0x003060E8
		internal override void buildsql()
		{
		}

		// Token: 0x06000CEC RID: 3308 RVA: 0x00307EEA File Offset: 0x003060EA
		internal override void clear()
		{
		}

		// Token: 0x06000CED RID: 3309 RVA: 0x00307EEC File Offset: 0x003060EC
		internal override string getasprettytext()
		{
			return "";
		}

		// Token: 0x06000CEE RID: 3310 RVA: 0x00307EF3 File Offset: 0x003060F3
		internal virtual void iterate(TVisitorAbs pvisitor)
		{
		}

		// Token: 0x1700025E RID: 606
		// (get) Token: 0x06000CEF RID: 3311 RVA: 0x00307EF5 File Offset: 0x003060F5
		// (set) Token: 0x06000CF0 RID: 3312 RVA: 0x00307EFD File Offset: 0x003060FD
		public virtual TObjectName ModuleName
		{
			get
			{
				return this.moduleName;
			}
			set
			{
				this.moduleName = value;
			}
		}

		// Token: 0x1700025F RID: 607
		// (get) Token: 0x06000CF1 RID: 3313 RVA: 0x00307F06 File Offset: 0x00306106
		// (set) Token: 0x06000CF2 RID: 3314 RVA: 0x00307F0E File Offset: 0x0030610E
		public virtual TExecParameterList Parameters
		{
			get
			{
				return this.parameters;
			}
			set
			{
				this.parameters = value;
			}
		}

		// Token: 0x17000260 RID: 608
		// (get) Token: 0x06000CF3 RID: 3315 RVA: 0x00307F17 File Offset: 0x00306117
		// (set) Token: 0x06000CF4 RID: 3316 RVA: 0x00307F1F File Offset: 0x0030611F
		public virtual TObjectName ReturnStatus
		{
			get
			{
				return this.returnStatus;
			}
			set
			{
				this.returnStatus = value;
			}
		}

		// Token: 0x17000261 RID: 609
		// (get) Token: 0x06000CF5 RID: 3317 RVA: 0x00307F28 File Offset: 0x00306128
		// (set) Token: 0x06000CF6 RID: 3318 RVA: 0x00307F30 File Offset: 0x00306130
		public virtual TExpressionList StringValues
		{
			get
			{
				return this.stringValues;
			}
			set
			{
				this.stringValues = value;
			}
		}

		// Token: 0x17000262 RID: 610
		// (get) Token: 0x06000CF7 RID: 3319 RVA: 0x00307F39 File Offset: 0x00306139
		// (set) Token: 0x06000CF8 RID: 3320 RVA: 0x00307F41 File Offset: 0x00306141
		public virtual int ExecType
		{
			get
			{
				return this.execType;
			}
			set
			{
				this.execType = value;
			}
		}

		// Token: 0x06000CF9 RID: 3321 RVA: 0x00307F4C File Offset: 0x0030614C
		private bool isValidProcedureCall(TSourceTokenList stList, TSyntaxError err)
		{
			bool flag = false;
			if (stList.size() <= 1)
			{
				return false;
			}
			TSourceToken tsourceToken = stList.get(0);
			if (tsourceToken.tokencode == 314)
			{
				TSourceToken tsourceToken2 = stList.nextsolidtoken(tsourceToken, 1, false);
				err.hint = "Unknown object type in drop statement";
				if (tsourceToken2 != null)
				{
					err.tokentext = tsourceToken2.ToString();
					err.lineNo = tsourceToken2.lineNo;
					err.columnNo = tsourceToken2.columnNo;
				}
				return false;
			}
			return stList.get(1).tokentype == ETokenType.ttperiod || tsourceToken.ToString().ToLower().StartsWith("sp") || (!tsourceToken.ToString().ToLower().StartsWith("select") && !tsourceToken.ToString().ToLower().StartsWith("del") && !tsourceToken.ToString().ToLower().StartsWith("update") && !tsourceToken.ToString().ToLower().StartsWith("insert") && !tsourceToken.ToString().ToLower().StartsWith("create") && flag);
		}

		// Token: 0x06000CFA RID: 3322 RVA: 0x00308064 File Offset: 0x00306264
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			if (!(this.rootNode is TExecuteSqlNode))
			{
				if (this.sourcetokenlist.size() > 0)
				{
					TSourceToken tsourceToken = this.sourcetokenlist.get(0);
					TSyntaxError tsyntaxError = new TSyntaxError(tsourceToken.ToString(), tsourceToken.lineNo, tsourceToken.columnNo, "syntax error", EErrorType.sperror, 10111);
					if (!this.isValidProcedureCall(this.sourcetokenlist, tsyntaxError))
					{
						this.parseerrormessagehandle(tsyntaxError);
					}
				}
				return -1;
			}
			TExecuteSqlNode texecuteSqlNode = (TExecuteSqlNode)this.rootNode;
			this.execType = texecuteSqlNode.ExecType;
			base.doParseStatement(psql);
			if (texecuteSqlNode.ExecType == 0)
			{
				this.moduleName = texecuteSqlNode.ModuleName;
				this.parameters = texecuteSqlNode.Parameters;
				this.returnStatus = texecuteSqlNode.ReturnStatus;
			}
			else if (texecuteSqlNode.ExecType == 1)
			{
				this.stringValues = texecuteSqlNode.StringValues;
			}
			else if (texecuteSqlNode.ExecType == 3 && this.sourcetokenlist.size() > 0)
			{
				TSourceToken tsourceToken2 = this.sourcetokenlist.get(0);
				TSyntaxError tsyntaxError2 = new TSyntaxError(tsourceToken2.ToString(), tsourceToken2.lineNo, tsourceToken2.columnNo, "syntax error", EErrorType.sperror, 10111);
				if (!this.isValidProcedureCall(this.sourcetokenlist, tsyntaxError2))
				{
					this.parseerrormessagehandle(tsyntaxError2);
				}
				this.moduleName = new TObjectName();
				this.moduleName.GSharpSqlParser = this.GSharpSqlParser;
				int num = 0;
				int num2 = 0;
				while (num2 < this.sourcetokenlist.size() && this.sourcetokenlist.get(num2).tokentype != ETokenType.ttwhitespace && this.sourcetokenlist.get(num2).tokentype != ETokenType.ttreturn && this.sourcetokenlist.get(num2).tokentype != ETokenType.ttsemicolon)
				{
					num++;
					num2++;
				}
				switch (num)
				{
				case 1:
					this.moduleName.init(this.sourcetokenlist.get(0));
					goto IL_29F;
				case 3:
					this.moduleName.init(this.sourcetokenlist.get(0), this.sourcetokenlist.get(2));
					goto IL_29F;
				case 5:
					this.moduleName.init(this.sourcetokenlist.get(0), this.sourcetokenlist.get(2), this.sourcetokenlist.get(4));
					goto IL_29F;
				case 7:
					this.moduleName.init(this.sourcetokenlist.get(0), this.sourcetokenlist.get(2), this.sourcetokenlist.get(4), this.sourcetokenlist.get(6));
					goto IL_29F;
				}
				this.moduleName = null;
				IL_29F:
				if (this.moduleName != null)
				{
					this.moduleName.ObjectType = 12;
				}
			}
			return 0;
		}

		// Token: 0x06000CFB RID: 3323 RVA: 0x00308326 File Offset: 0x00306526
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x06000CFC RID: 3324 RVA: 0x00308336 File Offset: 0x00306536
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x040012F6 RID: 4854
		private TObjectName moduleName;

		// Token: 0x040012F7 RID: 4855
		private TObjectName returnStatus;

		// Token: 0x040012F8 RID: 4856
		private TExecParameterList parameters;

		// Token: 0x040012F9 RID: 4857
		private TExpressionList stringValues;

		// Token: 0x040012FA RID: 4858
		private int execType;
	}
}
